
//
//  LM2SelectView.m
//  WelfareManager
//
//  Created by longmin on 17/5/17.
//  Copyright © 2017年 timtian. All rights reserved.
//

#import "LM2SelectView.h"
#import "LMSelecteButton.h"

@interface LM2SelectView ()

@property(nonatomic, strong) UILabel *titleLabel;

@property(nonatomic, strong) UIView *line;

@property(nonatomic, strong) LMSelecteButton *leftItem;
@property(nonatomic, strong) LMSelecteButton *leftItem1;

@property(nonatomic, strong) LMSelecteButton *rightItem;
@property(nonatomic, strong) LMSelecteButton *rightItem1;

@end

@implementation LM2SelectView

#pragma mark - 生命周期

- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        [self addSubview:self.titleLabel];
        [self addSubview:self.line];
        [self addSubview:self.leftItem];
        [self addSubview:self.rightItem];
        [self addSubview:self.leftItem1];
        [self addSubview:self.rightItem1];
       
    }
    return self;
}

#pragma mark - Event

- (void)leftSelect {
    self.rightItem.select = NO;
    self.leftItem.select = YES;
    self.rightItem1.select = NO;
    self.leftItem1.select = NO;
    self.selectType = 0;
    if (self.customType) {
        self.customType(self.selectType);
    }
    
}

- (void)leftSelect1 {
    self.rightItem.select = NO;
    self.leftItem.select = NO;
    self.rightItem1.select = NO;
    self.leftItem1.select = YES;
    self.selectType = 1;
    if (self.customType) {
        self.customType(self.selectType);
    }
    
}

- (void)rightSelect {
    self.leftItem.select = NO;
    self.rightItem.select = YES;
    self.rightItem1.select = NO;
    self.leftItem1.select = NO;
    self.selectType = 2;
    if (self.customType) {
        self.customType(self.selectType);
    }
    
}

- (void)rightSelect1 {
    self.leftItem.select = NO;
    self.rightItem.select = NO;
    self.rightItem1.select = YES;
    self.leftItem1.select = NO;
    self.selectType = 3;
    if (self.customType) {
        self.customType(self.selectType);
    }
    
}

#pragma mark - Public

+ (instancetype)selectViewWithTitle:(NSString *)title Left:(NSString *)left Left2:(NSString *)left2 right:(NSString *)right right2:(NSString *)right2 {
    
    LM2SelectView *selectView = [[LM2SelectView alloc] init];
    selectView.backgroundColor = [UIColor whiteColor];
    
    selectView.width = __kScreenWidth;
    selectView.height = 55;
    
    selectView.titleLabel.text = title;
    selectView.leftItem.title = left;
    selectView.rightItem.title = right;
    selectView.leftItem1.title = left2;
    selectView.rightItem1.title = right2;
    [selectView leftSelect];
    
    return selectView;
}

- (void)setShowLine:(BOOL)showLine {
    self.line.hidden = !showLine;
}

#pragma mark - Private
#pragma mark - 数据源和代理方法
#pragma mark - UIView -> 下面放继承自UIView的方法

- (void)layoutSubviews {
    [super layoutSubviews];
    
    [self.titleLabel sizeToFit];
    self.titleLabel.centerY = self.height * 0.5;
    self.titleLabel.left = 15;
    
    self.leftItem.centerY = self.titleLabel.centerY;
    self.leftItem.left = 108 * __kwRatio;
    
    self.leftItem1.centerY = self.titleLabel.centerY;
    self.leftItem1.left = self.leftItem.right+HGADPT(10);
    
    self.rightItem.centerY = self.titleLabel.centerY;
    self.rightItem.left = self.leftItem1.right+HGADPT(10);
    
    self.rightItem1.centerY = self.titleLabel.centerY;
    self.rightItem1.left = self.rightItem.right+HGADPT(10);
    
    self.line.height = 0.5;
    self.line.width = self.width - 15;
    self.line.bottom = self.height;
    self.line.right = self.width;
    
}

#pragma mark - set方法和get方法

- (UILabel *)titleLabel {
    if (_titleLabel == nil) {
        _titleLabel = [[UILabel alloc] init];
        _titleLabel.font = _kFont32;
        _titleLabel.textColor = kColor3C3C3C;
    }
    return _titleLabel;
}

- (UIView *)line {
    if (_line == nil) {
        _line = [[UIView alloc] init];
        _line.backgroundColor = kColorD9D9D9;
    }
    return _line;
}

- (LMSelecteButton *)leftItem {
    if (_leftItem == nil) {
        __weak typeof(self) weakSelf = self;
        _leftItem = [LMSelecteButton selectButtonWithFont:_kFontSub
                                                    title:@"A1"
                                                    color:kColorA6A6A6
                                             clickHandler:^(BOOL isSelect) {
            [weakSelf leftSelect];
        }];
    }
    return _leftItem;
}
- (LMSelecteButton *)leftItem1 {
    if (_leftItem1 == nil) {
        __weak typeof(self) weakSelf = self;
        _leftItem1 = [LMSelecteButton selectButtonWithFont:_kFontSub
                                                    title:@"A2"
                                                    color:kColorA6A6A6
                                             clickHandler:^(BOOL isSelect) {
                                                 [weakSelf leftSelect1];
                                             }];
    }
    return _leftItem1;
}

- (LMSelecteButton *)rightItem {
    if (_rightItem == nil) {
        __weak typeof(self) weakSelf = self;
        _rightItem = [LMSelecteButton selectButtonWithFont:_kFontSub
                                                    title:@"B1"
                                                    color:kColorA6A6A6
                                             clickHandler:^(BOOL isSelect) {
                                                 [weakSelf rightSelect];
                                             }];
    }
    return _rightItem;
}
- (LMSelecteButton *)rightItem1 {
    if (_rightItem1 == nil) {
        __weak typeof(self) weakSelf = self;
        _rightItem1 = [LMSelecteButton selectButtonWithFont:_kFontSub
                                                     title:@"B2"
                                                     color:kColorA6A6A6
                                              clickHandler:^(BOOL isSelect) {
                                                  [weakSelf rightSelect1];
                                              }];
    }
    return _rightItem1;
}

@end
